﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;
using Touch2Like.Model;
using Touch2Like.SharedLibrary;

namespace Touch2Like.Web.api
{
    public partial class tag : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();

            Touch2Like.DAL.UserDAL user = new Touch2Like.DAL.UserDAL();
            UserInfo info = user.GetUserByNameAndEmail(GlobalManager.RetrieveUserType.Email, Request["uname"]);

            JObject jo = new JObject();

            if (info != null)
            {
                //is taguid >> user.tags
                string sign = WebUtility.GetMD5String(info.UserName + ":" + info.Password + ":" + Request["taguid"]);

                if (Request["sign"] == sign)
                {
                    jo["success"] = "yes";
                    jo["uname"] = info.UserName;
                    jo["taguid"] = Request["taguid"];
                    jo["msg"] = "";
                }
                else
                {
                    jo["success"] = "no";
                    jo["uname"] = info.UserName;
                    jo["taguid"] = Request["taguid"];
                    jo["msg"] = "sign failed";
                }
            }
            else
            {
                jo["success"] = "no";
                jo["uname"] = Request["uname"];
                jo["taguid"] = Request["taguid"];
                jo["msg"] = "user failed";
            }

            Response.Write(jo.ToString());

            Response.End();
        }
    }
}